<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    {js href='/public/static/jquery/jquery-1.11.0.min.js' /}
    {js href='/public/static/layui/layui.js' /}
    {CSS href="/public/static/layui/css/layui.css" /}
    {CSS href="__ADDONSTATIC__/css/style.css" /}
    {js href='__STATIC__/zclip/jquery.zclip.min.js' /}
</head>
<body>
<div style="padding: 0px 10px;">
    <div>

        <!--<a href="{:addonUrl('addFromMaterial1')}"  class="layui-btn layui-btn-normal layui-btn-sm rha-nav-title">从临时素材库添加文章</a>-->
        <a href="{:addonUrl('addFromMaterial')}"  class="layui-btn layui-btn-normal layui-btn-sm rha-nav-title">从素材库添加文章</a>
    </div>

    <form class="layui-form" action="">
        <table class="layui-table">
            <colgroup>
                <col width="120">
                <col>
                <col width="100">
                <col width="90">
                <col width="100">
                <col width="90">
                <col width="90">
                <col width="150">
            </colgroup>
            <thead>
            <tr>
                <th>缩略图</th>
                <th>文章标题</th>
                <th>所属栏目</th>
                <th>浏览次数</th>
                <th>创建时间</th>
                <th>发布</th>
                <th>置顶</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="article_list" id="v" }
            <tr>
                <td><a href="{$v.cover}" target="_blank" ><img src="{$v.cover}" alt="" width="90" height="60" ></a></td>
                <td>{$v.title}</td>
                <td>{$v.columns_name}</td>
                <td>{$v.views}</td>
                <td>{$v.add_time}</td>
                <td> <form class="layui-form" action=""><input type="checkbox" data-id="{$v.id}" lay-filter="showArticle" {if condition="$v.show == 1"}checked{/if} lay-skin="switch" name="show"/></form></td>
                <td> <form class="layui-form" action=""><input type="checkbox" data-id="{$v.id}" lay-filter="setTop" {if condition="$v.top == 1"}checked{/if} lay-skin="switch" name="top"/></form></td>
                <td>
                    <a class="rha-bt-a" target="_blank" href="{:addonUrl('preview/show',['id'=>$v.id])}">预览</a>
                    <a class="rha-bt-a copyUrls"  href="javascript:;" >复制连接</a>
                    <div style="display: none" class="copyUrl">{$v.url}</div>
                    <a class="rha-bt-a" href="{:addonUrl('editArticle',['id'=>$v.id])}">编辑</a>
                    <a class="rha-bt-a" onclick="delForms('{$v.id}')" href="javascript:;">删除</a>
                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
        {$page|raw}
        </form>

</div>

<script>
    $(function () {
        $('.copyUrls').zclip({
            path: '__STATIC__/zclip/ZeroClipboard.swf',
            copy: function(){
                parent.layer.msg("复制成功");
                return $(this).next('.copyUrl').text();
            },
            afterCopy: function(){

            }
        });
    })
    layui.use(['form', 'layer'], function () {
        var form = layui.form;
        form.on('switch(showArticle)', function(data){
            var show = 0;
            if($(data.elem).prop("checked")) {
                show = 1;
            }
            var id = $(data.elem).attr('data-id');
            $.post("{:addonUrl('showArticle')}",{fid:id,show:show},function (res) {

            });
            form.render('checkbox');
        });
    });

    layui.use(['form', 'layer'], function () {
        var form = layui.form;
        form.on('switch(setTop)', function(data){
            var show = 0;
            if($(data.elem).prop("checked")) {
                show = 1;
            }
            var id = $(data.elem).attr('data-id');
            $.post("{:addonUrl('setTop')}",{fid:id,show:show},function (res) {

            });
            form.render('checkbox');
        });
    });

    function delForms(id) {
        parent.layer.confirm('确定删除吗？', {
            btn: ['是','不'], //按钮
            offset: ['20%', '30%'],
            shade: 0.1,
        }, function(){
            $.post("{:addonUrl('delArticle')}",{fid:id},function (res) {
                if(res.status==1){
                    parent.layer.alert(res.msg,function (index) {
                        window.location.reload();
                        parent.layer.close(index);
                    })

                }else{
                    parent.layer.alert(res.msg)
                }
            })
        }, function(){

        });
    }



</script>
</body>
</html>